<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript">
    var fun = function() {
        /*127.0.0.1
         115.28.46.122-115.28.46.129
         15.28.46.122;15.28.49.122*/
    }
    var lines = new String(fun);
    var result=lines.substring(lines.indexOf("/*")+2,lines.lastIndexOf("*/"));
    alert(result);
    str = $.trim(result);
    //1.去掉 回车换行 2.去掉 - 3.去掉 ； 4.去掉空格 5.按照 # 分割 返回一个数组
    strArrary= str.replace(/\n/g,"#").replace(/-/g,"#").replace(/;/g,"#").replace(/\s/g,'').split("#");
    alert(strArrary.length);
    for(var i=0;i<strArrary.length;i++) {
        alert(strArrary[i]);
       alert(isValidIP(strArrary[i]));
    }
    function isValidIP(ip)
    {
        var reg =  /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/
        return reg.test(ip);
    }
</script>
</body>
</html>